/* ***************************************************************************************** */
/* ******************* Produce summary statistics reported in the paper  ******************* */
/* ***************************************************************************************** */

*** Panel A of Table 1;
data summary; set temp.iss_votes_ret;
  if issue ne '';
  if 0 < abs(margin) <= .2 then contentious = 1; else if abs(margin) > .2 then contentious = 0;

proc means data = summary n mean std p25 median p75;
  var WinVote voteAgainstMgmt iss_conform; 
run;

proc means data = summary n mean std p25 median p75; class contentious;
  var WinVote voteAgainstMgmt iss_conform; 
run;



*** Panel B of Table 1;
proc sort data = summary; by issAgendaItemId;

proc means data = summary noprint; by issAgendaItemId;
  var WinVote; where 0 < abs(margin) <= .2;
  output out = proposal_list1a (drop=_type_ _freq_) n = num_votes mean = mu_WinVote;

proc sort data = summary nodupkey out = summary2; by issAgendaItemId itemonagendaid;

proc means data = summary2 noprint; by issAgendaItemId;
  var WinVote; where 0 < abs(margin) <= .2;
  output out = proposal_list1b (drop=_type_ _freq_) n = num_proposals;

data proposal_list; merge proposal_list1a proposal_list1b; by issAgendaItemId;

proc sql;
  create table proposal_list as
  select a.*, b.AgendaGeneralDesc, b.issue
  from proposal_list as a, drop1.Proposal_list as b
  where a.ISSAgendaItemID = b.ISSAgendaItemID;
quit;

proc sort data = proposal_list nodupkey; by issue issAgendaItemId; 

proc means n sum;
  var num_votes;
run;

proc sort data = proposal_list; by descending num_votes ISSAgendaItemID; run;

proc export data= proposal_list 
            outfile= "D:\Dropbox\InformedVoting\proposal_list.xlsx" 
            dbms=xlsx replace;
run;




*** Panel A of Table 2;
data sum; set temp.informed_fund_level;
  mret_style_adj_pr12 = mret_style_adj_pr12*100;
  family_tna = family_tna/1000;

proc means data = sum n mean std p25 median p75;
  var vote_alpha informed mtna family_tna fund_age index_fund2 mret_style_adj_pr12 mret_style_adj_std flow_style_adj_pr12 flow_style_adj_std num_stocks turnover expenses2 total_loads2 size_score value_score mom_score iss_conform_all voteagainstmgmt_all sole_or_independent_all;
run;


*** Panel B of Table 2;
proc means data = temp.proposals n mean std p25 median p75; 
  var net_win_informed net_win_uninformed car63d_ff4 car126d_ff4 car252d_ff4 car378d_ff4 car63d_dgtw car126d_dgtw car252d_dgtw car378d_dgtw mgmt_win iss_win mgmt_lost_nc at mb car_pr252d_m leverage_b capex sp500 mfo nanalyst;
run;



*** Panel C of Table 2;
proc means data = temp.informed_sue_annual n mean std p25 median p75; 
  var frac_informed roa_post sue_post frac_mgmt_win frac_iss_win at mb xret1y leverage_b capex sp500 mfo nanalyst;
run;




**** Table IA-2, Panel A: Ranking of mutual funds;
proc sql;
  create table list as
  select a.*, b.fundName, b.institutionName
  from temp.informed_fund_level as a, drop.iss_crspmf as b
  where a.wficn = b.wficn and a.crsp_cl_grp = b.crsp_cl_grp and year(b.st_date) <= a.year <= year(b.end_date);
quit;

data list; set list;
  if institutionName = 'Dreyfus Investment Advisors, Inc.' then institutionName = 'The Dreyfus Corporation';
  if institutionName = 'Barclays Global Investors NA (CA)' and year >= 2010 then institutionName = 'BlackRock Advisors, Inc.';

proc sort nodupkey; by institutionName wficn crsp_cl_grp year;

proc sort data = list nodupkey; by wficn crsp_cl_grp year; run;

proc means n mean median min p1 p99 max;
  var vote_alpha num_votes; run;

%winsor(dsetin=list, dsetout=list, byvar=year, vars=vote_alpha, type=winsor, pctl=1 99); 

proc sort data = list; by wficn institutionName fundName;

proc means data = list noprint; by wficn institutionName fundName;
  var vote_alpha; weight num_votes;
  output out = list_funds1a (drop=_type_ _freq_) mean = vote_alpha;

proc means data = list noprint; by wficn institutionName fundName;
  var num_votes; 
  output out = list_funds1b (drop=_type_ _freq_) n = num_yrs sum = num_votes;

data list_funds; merge list_funds1a list_funds1b; by wficn institutionName fundName;

proc sort; by descending vote_alpha wficn;

data list_funds; set list_funds; by descending vote_alpha wficn;
  where num_yrs >= 5;
  i = _n_;

data top10_funds; set list_funds;
  if 1 <= i <= 10;
run;


proc export data= top10_funds 
            outfile= "D:\Dropbox\InformedVoting\Temp\top10_funds" 
            dbms=xlsx replace;
run;

proc sql;
  create table list as
  select a.*, b.fundName, b.institutionName
  from temp.informed_fund_level as a, drop.iss_crspmf as b
  where a.wficn = b.wficn and a.crsp_cl_grp = b.crsp_cl_grp and year(b.st_date) <= a.year <= year(b.end_date);
quit;

data list; set list;
  if institutionName = 'Dreyfus Investment Advisors, Inc.' then institutionName = 'The Dreyfus Corporation';
  if institutionName = 'Barclays Global Investors NA (CA)' and year >= 2010 then institutionName = 'BlackRock Advisors, Inc.';

proc sort nodupkey; by institutionName wficn crsp_cl_grp year;

%winsor(dsetin=list, dsetout=list, byvar=year, vars=vote_alpha, type=winsor, pctl=1 99); 

proc sort data = list; by institutionName year;

proc means data = list noprint; by institutionName year;
  var vote_alpha; weight num_votes;
  output out = list_family1a (drop=_type_ _freq_) mean = vote_alpha;

proc means data = list noprint; by institutionName year;
  var num_votes;
  output out = list_family1b (drop=_type_ _freq_) sum = num_votes n = num_funds;

data list_family; merge list_family1a list_family1b; by institutionName year;
  if num_funds >= 3;

proc means data = list noprint; by institutionName;
  var vote_alpha; weight num_votes;
  output out = list_family2a (drop=_type_ _freq_) mean = vote_alpha;

proc means data = list_family noprint; by institutionName;
  var num_funds;
  output out = list_family2b (drop=_type_ _freq_) mean = num_funds sum(num_votes) = num_votes n = num_years;

data list_family3; merge list_family2a list_family2b; by institutionName;

proc sort; by descending vote_alpha; where num_years >= 5 and num_votes >= 500; 

data top10_families; set list_family3;
  i = _n_;
  if 1 <= i <= 10;
run;
run;



proc export data= top10_families 
            outfile= "D:\Dropbox\InformedVoting\Temp\top10_families" 
            dbms=xlsx replace;
run;


